package com.zscat.mallplus;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.Time;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * 应用启动入口
 * https://github.com/shenzhuan/mallplus on 2018/4/26.
 */
@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
@MapperScan({"com.zscat.mallplus.mapper", "com.zscat.mallplus.ums.mapper",
        "com.zscat.mallplus.sms.mapper", "com.zscat.mallplus.cms.mapper",
        "com.zscat.mallplus.sys.mapper", "com.zscat.mallplus.oms.mapper",
        "com.zscat.mallplus.pms.mapper","com.zscat.mallplus.active.mapper",
        "com.zscat.mallplus.email.mapper"})
@EnableTransactionManagement
@EnableScheduling
public class MallAdminApplication {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Bean
    ApplicationRunner mApplicationRunner(){
        return args -> {
            log.info("***************************************");
            log.info(" // ");
            log.info(" // ");
            log.info("Redis Link detection");
            log.info("Redis 链接检测");
            stringRedisTemplate.opsForValue().set(UUID.randomUUID().toString(),UUID.randomUUID().toString(), 20,TimeUnit.SECONDS);
            log.info(" // ");
            log.info("     [SUCCESS]     ");
            log.info(" // ");
            log.info("***************************************");
        };
    }




    public static void main(String[] args)  throws UnknownHostException {
        System.out.println("start-------------");
        // SpringApplication.run(MallPortalApplication.class, args);
        ConfigurableApplicationContext application = SpringApplication.run(MallAdminApplication.class, args);
        Environment env = application.getEnvironment();
        String ip = InetAddress.getLocalHost().getHostAddress();
        String port = env.getProperty("server.port");

        log.info("\n----------------------------------------------------------\n\t" +
                "Application mallplus-Boot is running! Access URLs:\n\t" +
                "Local: \t\thttp://localhost:" + port  + "/\n\t" +
                "External: \thttp://" + ip + ":" + port  + "/\n\t" +
                "swagger-ui: \thttp://" + ip + ":" + port  + "/swagger-ui.html\n\t" +
                "https://gitee.com/zscat/mallplus/wikis/pages/preview?sort_id=2168368&doc_id=326093\n\t"+
                "-----------------页面请部署 mallplus-admin-web-----------------------------------------");
    }
}
